//package com.zxw.cloud.gateway.filter;
//
//import lombok.extern.slf4j.Slf4j;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Component;
//
//import javax.servlet.*;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//
//@Slf4j
//@Component
//@SuppressWarnings("unused")
//public class CorsFilter implements Filter{
//
//    @Value("${com.cors}")
//    private String cors;
//
//    @Value("${com.corsheader}")
//    private String corsHeader;
//
//    @Override
//    public void init(FilterConfig filterConfig) throws ServletException {
//
//    }
//
//    @Override
//    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
//        HttpServletResponse response = (HttpServletResponse) res;
//        //logger.debug("CORS控制");
//        // 允许哪些域名跨域
//        response.setHeader("Access-Control-Allow-Origin", cors);
//        // 是否允许cookies传输
//        response.setHeader("Access-Control-Allow-Credentials", "true");
//        // 允许header中哪些参数传输
//        response.setHeader("Access-Control-Allow-Headers", corsHeader);
//        // 告诉CDN等，响应是基于请求者Origin头值进行协商的。
//        response.setHeader("Vary", "Origin");
//        if(((HttpServletRequest)req).getMethod().toUpperCase().equals("OPTIONS")){
//            return;
//        }
//        chain.doFilter(req, res);
//    }
//
//    @Override
//    public void destroy() {
//
//    }
//}